package powerBusiness;

import easyDAO.SqlDispatch;
import impl.TestServerBusinessImpl;
import models.Md5;
import models.MyConfig;
import models.ReturnJson;
import models.SqlReturnModel;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yangxianming on 2021/3/30.
 * 重置密码
 */
public class RenewPW implements TestServerBusinessImpl {
    @Override
    public String doIt(HttpServletRequest request, MyConfig myConfig) {
        ReturnJson rj = new ReturnJson();
        String username = request.getParameter("username");
        SqlDispatch sqlDispatch = new SqlDispatch(myConfig);
        String md5PW =  Md5.md5PlusSalt("111111");
        String set = " SET password = '"+md5PW+"' ";
        String where = " WHERE username='"+username+"' ";
        String sql2 = "UPDATE `user` " + set + where;
        SqlReturnModel srm = sqlDispatch.update(sql2);
        if (srm.getIsSuccess()){
            rj.setResult("修改成功");
        }else {
            rj.setResult(0, null, srm.getFailingReason());
        }
        return rj.toString();
    }
}
